let arr = [1, 2, [3, [4]]]


function flattenArray(arr) {
      let newArr = []
      for (let key in arr) {
        if (Array.isArray(arr[key])) {
          //newArr.push(...flattenArray(arr[key]))
          newArr = newArr.concat(flattenArray(arr[key]))// concat() 会返回一个新数组
        } else {
          newArr.push(arr[key])
        }
      }
      return newArr
    }
    console.log(flattenArray(arr));


console.log(flattenArray(arr));
